package com.beiding.workordersystem.orders.generalorder.controller;

import com.beiding.workordersystem.common.beans.MsgSender;
import com.beiding.workordersystem.common.dao.MPage;
import com.beiding.workordersystem.common.standard.R;
import com.beiding.workordersystem.orders.generalorder.service.OrderProcessService;
import com.beiding.workordersystem.orders.generalorder.vo.ChangePrincipalVo;
import com.beiding.workordersystem.orders.generalorder.vo.ReportExceptionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/process")
public class OrderProcessController {

    @Autowired
    private OrderProcessService orderProcessService;

    @GetMapping("/my")
    R myProcesses(MPage mPage) {
        return R.ok(orderProcessService.getMyProcesses(mPage));
    }


    @PostMapping("/reportException")
    R reportException(@RequestBody @Validated ReportExceptionVo vo){
        orderProcessService.reportException(vo.getProcessId(), vo.getException());
        return R.ok();
    }

    @PostMapping("/accept")
    R accept(@RequestBody String[] ids) {
        orderProcessService.accept(ids);
        return R.ok();
    }

    @PostMapping("/changePrincipal")
    @PreAuthorize("hasAnyAuthority('generalOrder_orderProcess_designate')")
    R changePrincipal(@RequestBody @Validated ChangePrincipalVo vo) {
        orderProcessService.changePrincipal(vo.getProcessId(), vo.getPrincipalId());
        return R.ok();
    }

    @GetMapping("/finish")
    R finish(@RequestParam String id, boolean sendMsg) {
        orderProcessService.finish(id, sendMsg);
        return R.ok();
    }

    @Autowired
    private MsgSender sender;

    @GetMapping("/testSend")
    R test(){
        Map<String, String> params = new HashMap<>();
        params.put("name", UUID.randomUUID().toString());
        params.put("orderId", "xxxxxxxxxxxxxxxxxx");
        params.put("processNumber", "1");
        params.put("processDetails", "xxxxxxxxxxxxxx");
        params.put("url", "http//测试详情");

        System.out.println("http://localhost/loopOrder/passApplyForActiveTaxCategoriesAndCycle/GvBlAsFxDsCmAzIyIdAdGkDaCsFuFrBjHbFvAkDkJoGzAdCsCkAqDiBwDtHfEzCgIuClAoEfEyCfBgCa".length());

        System.out.println();

//        sender.send("15615634868", "SMS_184110664", params);
        return R.ok();
    }




}
